package com.atguigu.gmall.seckill.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.activity.SeckillGoods;
import com.atguigu.gmall.model.order.OrderInfo;
import com.atguigu.gmall.seckill.firstcache.SeckillFirstcache;
import com.atguigu.gmall.seckill.service.SeckillGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2025/9/18 1:08
 */
@RestController
@RequestMapping("/rpc/inner/seckill")
public class RpcSeckillController {
    @Autowired
    private SeckillGoodsService seckillGoodsService;
    @Autowired
    SeckillFirstcache seckillFirstcache;

    @GetMapping("/seckillList")
    public Result<List<SeckillGoods>> seckillList(){
        //List<SeckillGoods> seckillGoodsList =seckillGoodsService.seckillListCurrDate();
        //从一级缓存中获取数据
        List<SeckillGoods> seckillCacheList = seckillFirstcache.getSeckillCacheList();
        return Result.ok(seckillCacheList);
    }
    @GetMapping("/seckillDetail")
    public Result<SeckillGoods> seckillDetail(@RequestParam("skuId") Long skuId){
        //SeckillGoods seckillGoods =seckillGoodsService.seckillDetail(skuId);
        //从一级缓存中获取数据
        SeckillGoods seckillCache = seckillFirstcache.getSeckillCache(skuId);
        return Result.ok(seckillCache);
    }
    @GetMapping("/orderDetails/{skuId}")
    public Result<OrderInfo> orderDetails(@RequestParam("skuId") Long skuId){
        OrderInfo orderInfo =seckillGoodsService.orderDetails(skuId);
        return Result.ok(orderInfo);
    }

}
